#include "members.h"

Owner::Owner() {
  Self_ = new Individual;
  db_ = new DataBase;
}

Owner::~Owner() {
  delete Self_;
  delete db_;
}

void Owner::GetID(const info& ID){
  Self_->buidid = ID.buildingid;
  Self_->name = ID.name;
  Self_->address = ID.address;
  Self_->connection = ID.Tel;
}

void Owner::AddMember(Individual *person) {
  db_->Insert(Self_->buidid, Self_->address, Self_->name,
              person->name, person->gender, person->age,
              person->connection, person->temperature, person->state);
}

void Owner::ModifyMember(int row, int column, QString newvalue) {
  db_->Update(tableMember, db_->MemberTHead.at(column+3), newvalue,
              Fmember_.at(row).at(3));
}

QList<QStringList>* Owner::GetAllMembers() {
  Fmember_ = (db_->Select(tableMember, Self_->name));
  return &Fmember_;
}

void Owner::DeleteMember(QString name) {
  db_->Delete(tableMember, name);
}

void Owner::AddBuy(BuyInfo *buy) {
  db_->Insert(Self_->buidid, Self_->address, Self_->name, Self_->connection,
              buy->goodsname, buy->goodsnumber, buy->ordertime);
}


QList<QStringList>* Owner::GetAllBuys() {
  Buy_ = (db_->Select(tableShopping, Self_->name));
  return &Buy_;
}

void Owner::DeleteBuy(QString name, QString ordertime) {
  db_->Shopping_delete(Self_->connection, name, ordertime);
}


Staff::Staff(){
  db_ = new DataBase;
  Self_ = new Individual;

}

void Staff::GetID(const info& ID){
  Self_->buidid = ID.buildingid;
  Self_->name = ID.name;

}

void Staff::AddIOinfo(IOinfo *IO) {
  db_->Insert(IO->date, IO->people.name, IO->people.connection,
              IO->intime, IO->outtime, IO->people.temperature, Self_->buidid);
}

void Staff::ModifyIOinfo(int row, int column, QString newvalue) {
  int col = column;
  db_->Update(db_->IOTHead.at(column), newvalue, IO_.at(row).at(0),
              IO_.at(row).at(2), IO_.at(row).at(3));
}

void Staff::DeleteIOinfo(QString date,QString tel,QString intime) {
  db_->IO_delete( date, tel, intime);
}

QList<QStringList>* Staff::GetAllIOs() {
  IO_ = db_->Select(tableIO,"buildingid",Self_->buidid);
  return &IO_;
}

QList<QStringList>* Staff::GetAllOwners() {
  Owner_ = db_->Select(tableOwner,"buildingid",Self_->buidid);
  return &Owner_;
}

QList<QStringList>* Staff::GetAllResidents() {
  Resident_ = db_->Select(tableMember,"buildingid", Self_->buidid);
  return &Resident_;
}


Staff::~Staff(){
  delete db_;
  delete Self_;

}


void Supervisor::AddOwner(Individual *person) {
  //在业主表和家属表中分别插入当前业主信息
  //业主表
  db_->Insert(person->buidid, person->address, person->name, person->gender,
              person->age, person->connection, person->temperature, person->state);
  //家属表
  db_->Insert(person->buidid, person->address, person->name,
              person->name, person->gender, person->age,
              person->connection, person->temperature, person->state);

}

void Supervisor::ModifyOwner(int row, int column, QString newvalue) {

  db_->Update(tableOwner, db_->OwnerTHead.at(column), newvalue,
              Owner_.at(row).at(2));
}

void Supervisor::DeleteOwner(QString name) {
  //删除此业主的业主信息
  db_->Delete(tableOwner, name);
}

void Supervisor::AddStaff(Individual *person) {
  db_->Insert(person->buidid, person->name, person->gender, person->age,
              person->connection, person->temperature, person->state);
}

void Supervisor::ModifyStaff(int row, int column, QString newvalue){
  db_->Update(tableStaff, db_->StaffTHead.at(column), newvalue,
              Staff_.at(row).at(1));
}

void Supervisor::DeleteStaff(QString name) {
  db_->Delete(tableStaff, name);
}

void Supervisor::AddIOinfo(IOinfo *IO) {
  db_->Insert(IO->date, IO->people.name, IO->people.connection,
              IO->intime, IO->outtime, IO->people.temperature, IO->buildid);
}


QList<QStringList>* Supervisor::GetAllOwners() {
  Owner_ = db_->SelectAll(tableOwner);
  return &Owner_;
}

QList<QStringList>* Supervisor::GetAllStaffs() {
  Staff_ = db_->SelectAll(tableStaff);
  return &Staff_;
}

QList<QStringList>* Supervisor::GetAllIOs() {
  IO_ = db_->SelectAll(tableIO);
  return &IO_;
}

void Volunteer::ModifyBuyTime(QString arrivetime, int row) {

  db_->Shopping_update(arrivetime, UnArrive_.at(row).at(3),
                       UnArrive_.at(row).at(4), UnArrive_.at(row).at(6));
}

QList<QStringList>* Volunteer::GetArrived(){
  Arrive_ = db_->Select(tableShopping,"statu", "已送达");
  return &Arrive_;
}

QList<QStringList>* Volunteer::GetUnArrived(){
  UnArrive_ = db_->Select(tableShopping,"statu", "未送达");
  return &UnArrive_;
}



Members::Members()
{

}
